<?php
namespace app\app\controller;

use app\common\controller\App;
use think\Db;
use think\Exception;


class User extends App
{
    protected $middleware = ['AppAuth'];



    public function user_info()
    {
        $uid=$this->getLoginUid();
        $user_info=model("Member")->where(['uid'=>$uid])->find();
        $user_info['head_image']=model("File")->getpath($user_info['head_img']);
        return $this->ok('请求成功');
    }


    //修改个人资料
    public function edit_info()
    {

        $data['head_img']=request()->param("head_img",'0','intval');
        $data['password']=request()->param("password",'');
        if (empty($data['password'])){
            return $this->fail('请输入密码');
        }
        $res=model("Member")->edit_info($data);

        if ($res){
            return $this->ok('修改资料成功');
        }else{

            return $this->fail('修改资料失败');
        }
    }

    //个人中心
    public function index()
    {
        $member=model("Member")->getAppLoginInfo();
        if (empty($member)){
            return $this->fail('用户不存在');
        }
        $member['head_img']=model("File")->getPath($member['head_img']);
        $house=model("House")->where(['id'=>$member['house_id']])->value('title');
        $sushe=model("Room")->where(['id'=>$member['sushe_id']])->value('title');
        $member['sushe']=$house.$sushe;
        $member['sex']=$member['sex']==1?'男':'女';
        $member['zhuanye']=$member['zhuanye'];
        $member['class']=Db::name("Class")->where(['id'=>$member['class']])->value('title');
        $member['fdy']=Db::name("Admin")->where(['uid'=>$member['fdy']])->value('realname');
        return $this->ok('请求成功',$member);



    }


    //我的帖子
    public function my_tiezi()
    {

        $page=request()->param("page",1,'intval');
        $where=[];
        $uid=$this->getLoginUid();
        $where[]=['a.uid','=',$uid];

        $user_id=$this->getLoginUid();
        $list=model("Tiezi")
            ->alias("a")
            ->leftJoin("Member b","a.uid=b.uid")
            ->order("a.id desc")
            ->page(1,12)
            ->where($where)
            ->field("a.*,b.realname")
            ->select();
        if (!empty($list)){
            foreach ($list as $key=>$val){
                $list[$key]['create_time']=date("Y-m-d H:i",$val['create_time']);
                $list[$key]['image_path']=model("File")->getPath($val['image_id']);
                $list[$key]['can_del']=1;
            }
        }
        $data=[
            'list'=>$list
        ];
        return $this->ok('请求成功',$data);

    }



}
